package json;


import com.sun.xml.internal.txw2.output.IndentingXMLStreamWriter;
import com.sun.xml.internal.ws.streaming.DOMStreamReader;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;

import javax.management.Attribute;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.stream.XMLStreamReader;
import javax.xml.stream.XMLStreamWriter;
import java.beans.XMLDecoder;
import java.beans.XMLEncoder;
import java.io.*;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: leep
 * Date: 15-7-2
 * Time: 上午10:48
 * To change this template use File | Settings | File Templates.
 */
public class Main {
	public static void main(String[] args) throws IOException, ParserConfigurationException, SAXException, DocumentException {

		String ret1 = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
				"<CSubmitState xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://tempuri.org/\">\n" +
				"  <State>0</State>\n" +
				"  <MsgID>1512221711244402001</MsgID>\n" +
				"  <MsgState>提交成功</MsgState>\n" +
				"  <Reserve>0</Reserve>\n" +
				"</CSubmitState>";

		String ret = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
				"<CSubmitState xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://tempuri.org/\">\n" +
				"  <State>2001</State>\n" +
				"  <MsgID>0</MsgID>\n" +
				"  <MsgState>帐号:dlmpjkj1余额不足,过滤[1:150100207936,1:152586809564,1:1503997868,1:1503636750,1:19737171710]</MsgState>\n" +
				"  <Reserve>0</Reserve>\n" +
				"</CSubmitState>";
		org.dom4j.Document document = null;
		document = DocumentHelper.parseText(ret1);
		Element root = document.getRootElement();
		List<Attribute> list = root.attributes();

		System.out.println(getDomValue(ret1, "State").equals("0"));
	}

	public static String getDomValue(String xml, String node) throws DocumentException {
		org.dom4j.Document document = DocumentHelper.parseText(xml);
		Element root = document.getRootElement();
		Element student1Element = root.element(node);
		return student1Element.getStringValue();
	}
}
